﻿using System;

namespace Chengqbd.Core.Extensions
{
	public static class ReplaceExtensions
	{
		public static string ReplaceBankCard(this string input)
		{
			bool flag = !string.IsNullOrEmpty(input);
			string result;
			if (flag)
			{
				int length = input.Length;
				bool flag2 = length >= 12;
				if (flag2)
				{
					result = input.Remove(4, length - 8).Insert(4, new string('*', length - 8));
				}
				else
				{
					bool flag3 = length >= 8;
					if (flag3)
					{
						result = input.Remove(2, length - 4).Insert(2, new string('*', length - 4));
					}
					else
					{
						bool flag4 = length >= 4;
						if (flag4)
						{
							result = input.Substring(length - 2).PadLeft(length, '*');
						}
						else
						{
							result = input;
						}
					}
				}
			}
			else
			{
				result = input;
			}
			return result;
		}
        
		public static string ReplaceFullName(this string input)
		{
			bool flag = !string.IsNullOrEmpty(input) && input.Length > 1;
			string result;
			if (flag)
			{
				result = input.Substring(0, 1).PadRight(input.Length, '*');
			}
			else
			{
				result = input;
			}
			return result;
		}
        
		public static string ReplaceUserName(this string input, int length)
		{
			bool flag = !string.IsNullOrEmpty(input) && length < input.Length;
			string result;
			if (flag)
			{
				result = input.Substring(0, length).PadRight(input.Length, '*');
			}
			else
			{
				result = input;
			}
			return result;
		}
        
		public static string ReplaceIdCard(this string input)
		{
			bool flag = !string.IsNullOrEmpty(input);
			string result;
			if (flag)
			{
				int length = input.Length;
				bool flag2 = length >= 12;
				if (flag2)
				{
					result = input.Remove(4, length - 8).Insert(4, new string('*', length - 8));
				}
				else
				{
					bool flag3 = length >= 8;
					if (flag3)
					{
						result = input.Remove(2, length - 4).Insert(2, new string('*', length - 4));
					}
					else
					{
						bool flag4 = length >= 4;
						if (flag4)
						{
							result = input.Substring(0, length - 2).PadRight(length, '*');
						}
						else
						{
							result = input;
						}
					}
				}
			}
			else
			{
				result = input;
			}
			return result;
		}
        
		public static string ReplacePhone(this string input)
		{
			bool flag = !string.IsNullOrEmpty(input);
			string result;
			if (flag)
			{
				int length = input.Length;
				bool flag2 = length >= 8;
				if (flag2)
				{
					result = input.Remove(3, 4).Insert(3, "****");
				}
				else
				{
					bool flag3 = length >= 4;
					if (flag3)
					{
						result = input.Substring(length - 2).PadLeft(length, '*');
					}
					else
					{
						result = input;
					}
				}
			}
			else
			{
				result = input;
			}
			return result;
		}
        
		public static string ReplaceMail(this string input)
		{
			bool flag = !string.IsNullOrEmpty(input);
			string result;
			if (flag)
			{
				int num = input.IndexOf("@");
				bool flag2 = num >= 5;
				if (flag2)
				{
					result = input.Remove(3, num - 3).Insert(3, new string('*', num - 3));
				}
				else
				{
					result = input.Remove(1, num - 1).Insert(1, new string('*', num - 1));
				}
			}
			else
			{
				result = input;
			}
			return result;
		}
	}
}
